package org.example.controll;

import org.example.userBean.User;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;

import java.util.Date;
import java.util.List;

@Controller
@RequestMapping("/user")
//注意这一句，EnableWebMVC 无此句则会导致web后续使用@parambody无法运行
@EnableWebMvc
public class UserController {
    @RequestMapping("/save1")
    @ResponseBody
    public String save(){
        System.out.println("user save..");
        return "{'info':'springmvc'}";
    }
    @RequestMapping("/commParam")
    @ResponseBody
    public String commonParam(@RequestParam("name") String name){
        System.out.println("name==>"+name);

        return "{'module':'commonParam'}";

    }

    @RequestMapping("/getUser")
    @ResponseBody
    public  String Username(User user){
            System.out.println(user.toString());
            return "user";
    }
    @RequestMapping("/getList")
    @ResponseBody
    public String listParam(@RequestParam List<String> likes){
        System.out.println(likes);
        return "likes";

    }
    @RequestMapping("/Userpojo")
    @ResponseBody
    public String Userpojo (@RequestBody User user){
        System.out.println("pojo==>User"+user);
        return "pojo json";
    }
    @RequestMapping("/Date")
    @ResponseBody
    public String dataParam(Date date,
                            @DateTimeFormat(pattern = "yyyy-MM-dd") Date date1
    , @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") Date date2){
        System.out.println("data1"+date);
        System.out.println("data2"+date1);
        System.out.println("data2"+date2);
        return "data";
    }
//    访问文件，springMVC，默认屏蔽.html文件，只能访问.jsp文件

    @RequestMapping("/Jump")
    public String toJumpHtml(){
        System.out.println("123");
        return "page.jsp";
    }
//响应json数据
    @RequestMapping("/toUser")
    @ResponseBody
    public User toJson(){
        User user = new User();
        user.setAge(21);
        user.setName("沈维枫");
        return user;
    }

}